package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/admin/category")
@RestController
@Api(tags = "分类管理")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    //新增分类
    @PostMapping
    @ApiOperation("新增分类/套餐")
    public Result<String> saveCategory(@RequestBody CategoryDTO categoryDTO){
        categoryService.saveCategory(categoryDTO);
        return Result.success();
    }
    //分类分页查询
    @GetMapping("/page")
    @ApiOperation("分类分页查询")
    public Result<PageResult> queryByPage(CategoryPageQueryDTO categoryPageQueryDTO){
        PageResult pageResult = categoryService.queryByPage(categoryPageQueryDTO);
        return Result.success(pageResult);
    }
    //禁用启用分类
    @PostMapping("/status/{status}")
    @ApiOperation("启用禁用分类")
    public Result startOrStop(@PathVariable Integer status, Long id){
        categoryService.startOrStop(status,id);
        return Result.success();
    }
    //修改分类
    @PutMapping
    @ApiOperation("修改分类")
    public Result updateCategory(@RequestBody CategoryDTO categoryDTO){
        categoryService.updateCategory(categoryDTO);
        return Result.success();
    }
    //根据类型查询启用的分类，具体使用在分类页面没有涉及，具体在什么页面被使用？
    @GetMapping("/list")
    @ApiOperation("根据分类类型查询分类")
    public Result queryByType(Integer type){
        List<Category> categoryList= categoryService.queryByType(type);
        return Result.success(categoryList);
    }
    //删除分类
    @DeleteMapping
    @ApiOperation("根据id删除分类")
    public Result deleteById(@RequestParam Long id){
        categoryService.deleteById(id);
        return Result.success();
    }
}
